<template>
  <chart :option="option4" :height="`${height}px`" />
  <div class="flex">
    <chart :option="option5" :height="`${height}px`"  class="flex-1"/>
    <chart :option="option5_2" :height="`${height}px`"   class="flex-1"/>
  </div>
  <chart :option="option6" :height="`${height}px`" />
</template>

<script setup>
import chart from "@/components/chart/index";
import { echartsApi } from "@/api/statistics";
import {option4, option5,option5_2, option6, projectExpenditureTotal, projectFundsReceivedTotal} from "./chartData.js"
defineProps(["height"])
// 本年度学校按项目级别的立项情况 [国家级 部级 省级 地市级 校级（纵校+校级）横向课题(横向项目)]
const projectLevelStats = async () => {
  const res = await echartsApi.projectLevelStats()
  if (res.code == 200) {
    const item = res.data
    let seriesData = []
      seriesData.push(item.nationalLevel)
      seriesData.push(item.ministerialLevel)
      seriesData.push(item.provincialLevel)
      seriesData.push(item.municipalLevel)
      seriesData.push(item.schoolLevel)
      seriesData.push(item.horizontalProject)

      option4.value.series[0].data = seriesData
  }
};

// 本年度项目经费 [纵,横,校]
  const projectExpenditure = async () => {
  const res = await echartsApi.projectExpenditure()
  if (res.code == 200) {
    const item = res.data
    let seriesData = []
    seriesData.push({ value: item.zxExpenditure, name: '纵向项目'  })
    seriesData.push({ value: item.hxExpenditure, name: '横向项目'  })
    seriesData.push({ value: item.xjExpenditure, name: '校级项目'  })
    option5.value.series[0].data = seriesData
    projectExpenditureTotal.value = item.zxExpenditure + item.hxExpenditure + item.xjExpenditure
  }
};
// 本年度到账经费 [纵,横,校] 
  const projectFundsReceived = async () => {
  const res = await echartsApi.projectFundsReceived()
  if (res.code == 200) {
    const item = res.data
    let seriesData = []
    seriesData.push({ value: item.zxFundsReceived, name: '纵向项目'  })
    seriesData.push({ value: item.hxFundsReceived, name: '横向项目'  })
    seriesData.push({ value: item.xjFundsReceived, name: '校级项目'  })
    option5_2.value.series[0].data = seriesData
    projectFundsReceivedTotal.value = item.zxFundsReceived + item.hxFundsReceived + item.xjFundsReceived
  }
};

// 近五年专利发表
const fiveYPatentStats = async () => {
  const res = await echartsApi.fiveYPatentStats()
  if (res.code == 200) {
    let yAxisData = []
    let seriesData = []
    
    res.data.forEach((item, index) => {
      yAxisData.push(item.annual)
      seriesData.push(item.patentNum)
    })
    option6.value.yAxis.data = yAxisData
    option6.value.series[0].data = seriesData
  }
};

projectLevelStats()
projectExpenditure()
projectFundsReceived()
fiveYPatentStats()

</script>